var ns, app;
app = new Vue({
    el: '#app',
    data: {
        PrijectID:0,
        form: {},
        list: [],
        // list: [{
        //     year: 2022,
        //     month: 4,
        //     day: 28,
        //     count: 10
        // }, {
        //     year: 2022,
        //     month: 4,
        //     day: 29,
        //     count: 10
        // }],
        minDate: new Date(2022, 0, 1),
        maxDate: new Date(2022, 12, 31),
        showCalender: false,
        choosedatetime:'',
    },
    methods: {
        getdata: function () {
            var that = this;
            var options = {};
            options.PrijectID = that.PrijectID;
            options.DayTime = that.choosedatetime;
            options.action = "getpatroltaskoftheday";
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    that.form = data;
                } else {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            })
        },
        do_openResult: function (Rid,type) {
            var that = this;
            if(type==1){
                ns.openWin('xcResult_frm', '装修巡查',{
                    ID:Rid,
                    type:type
                });
            }
            if(type==2){
                ns.openWin('zxchayan_frm', '装修查验',{
                    ID:Rid,
                    type:type
                });
            }
            
        },
        //任务日历
        do_choose_time: function () {
            var that = this;
            that.showCalender = true;
            var options = {};
            options.PrijectID = that.PrijectID;
            options.action = "getalendartasks";
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    that.list=data.item_list;
                } else {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            })

        },
        getCount(day) {
            var that = this;
            var myDate = new Date(day.date);
            if (!myDate) {
                return 0;
            }
            var y = myDate.getFullYear();
            var m = myDate.getMonth() + 1;
            var d = myDate.getDate();
            var totalCount = 0;

            that.list.forEach(function (item) {
                var lsDate=new Date(item.DateTime);
                var lsy = lsDate.getFullYear();
                var lsm = lsDate.getMonth() + 1;
                var lsd = lsDate.getDate();   
                if (y == lsy && m == lsm && d == lsd) {
                    totalCount = item.count;
                    return false;
                }
            })
            return totalCount;
        },
        onConfirm(day) {
            var that = this;
            var y = day.getFullYear();
            var m = day.getMonth() + 1;
            var d = day.getDate();
            var nowdate = y + '年' + (m >= 10 ? m : '0' + m) + '月' + (d >= 10 ? d : '0' + d)+'日';
            that.showCalender = false;
            that.choosedatetime = nowdate;
            that.getdata();
        },
    }
});
apiready = function () {
    api.parseTapmode();
    ns = window.Foresight.Util;
    app.PrijectID = api.pageParam.PrijectID;
     //初始化时间
     var data = new Date();
     var year = data.getFullYear();
     var month = data.getMonth() + 1;
     var day=data.getDate();
     app.choosedatetime = year + '年' + (month >= 10 ? month : '0' + month)+'月'+(day >= 10 ? day : '0' + day)+'日';
    app.getdata();
    api.addEventListener({
        name: 'xuncha_updata'
    }, function () {
        app.getdata();
    });
    api.addEventListener({
        name: 'chayan_updata'
    }, function () {
        app.getdata();
    });
    api.addEventListener({
        name: 'zhuanjiao_updata'
    }, function () {
        app.getdata();
    });

};
